<?php
    require('functions.php');
    require('conn.cfg.php');
    require('includes/usps.php');    
    
    $msg ="ack=ko&msg=undefined";    
    
    if(isset($_REQUEST['action']) && $_REQUEST['action'] == 'usps'){
	
        $shipAddress1   = mysql_real_escape_string($_REQUEST['shipAddress1']);
	$shipAddress2   = mysql_real_escape_string($_REQUEST['shipAddress2']);
	$shipCity       = mysql_real_escape_string($_REQUEST['shipCity']);
	$shipState      = mysql_real_escape_string($_REQUEST['shipState']);
	$shipPostalcode = mysql_real_escape_string($_REQUEST['shipPostalcode']);
	
	$usps = new USPS;
	$usps->setServer(USPS_API_ADDRESS);
	$usps->setUserName(USPS_API_USER);	

	$usps->setAddress1(urlencode($shipAddress1));
	$usps->setAddress2(urlencode($shipAddress2));
	$usps->setCity(urlencode($shipCity));
	$usps->setState($shipState);
	$usps->setZipCode($shipPostalcode);
	
	$results = $usps->verify_address();	
	if($results->isOK == "Y"){
		$msg = "ack=ok&shipaddress1=".$results->address1."&shipaddress2=".$results->address2."&shipcity=".$results->city."&shipstate=".$results->state."&shippostalcode=".$results->zipcode;
	}else{
		$msg = "ack=ko&msg=shipping address is invalid";
	}	
    }
    
    dump($msg);
    echo $msg;
?>
